package com.ruoyi.common.config;

import com.qiniu.util.Auth;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 获取七牛云token
 *
 * @author Liu
 */
@Component
@ConfigurationProperties(prefix = "qiniu")
@Data
public class QiniuService {

    /**
     * ACCESS_KEY
     */
    private String ak;

    /**
     * SECRET_KEY
     */
    private String sk;

    /**
     * 空间
     */
    private String bucket;

    /**
     * 外链地址
     */
    private String url;

    private Auth auth;

    public String getToken() {
        if (Objects.isNull(auth)) {
            auth = Auth.create(ak, sk);
        }
        return auth.uploadToken(bucket);
    }
}
